Skip to content

fix: auto-adapt LeRobot state dimension instead of raising ValueError#82

Merged
cagataycali merged 3 commits intostrands-labs:mainfrom
cagataycali:fix/lerobot-state-dim-adapt
Apr 3, 2026
Merged

fix: auto-adapt LeRobot state dimension instead of raising ValueError#82
cagataycali merged 3 commits intostrands-labs:mainfrom
cagataycali:fix/lerobot-state-dim-adapt

Conversation

@cagataycali
Copy link
Copy Markdown
Member

TL;DR

When a robot exposes more joints than the policy was trained on (e.g. aloha has 16 joints but ACT expects 14), the policy raised a hard ValueError during inference. This fix auto-adapts state dimensions — truncate excess or zero-pad if fewer — with debug logging.

What changed

File Change
strands_robots/policies/lerobot_local/policy.py Replace ValueError with truncate/zero-pad + debug logging
tests/test_lerobot_local.py Update test to assert pad behavior instead of raises

Why

This is the standard approach in robotics — LeRobot's own teleoperation code does the same. Hard crashing on dimension mismatch makes sim↔real transfer fragile and prevents running policies trained on one embodiment on another with different joint counts.

# Before: Hard crash
if len(state_values) != expected_dim:
    raise ValueError(f"State dimension mismatch: got {len(state_values)}...")

# After: Auto-adapt with logging
if len(state_values) > expected_dim:
    logger.debug("State dim %d > model expects %d — truncating", ...)
    state_values = state_values[:expected_dim]
elif len(state_values) < expected_dim:
    logger.debug("State dim %d < model expects %d — zero-padding", ...)
    state_values.extend([0.0] * (expected_dim - len(state_values)))

Testing

  • ✅ All 266 existing tests pass
  • ✅ Updated test_state_padded_to_expected_dim to verify auto-pad behavior
  • ✅ Lint clean (ruff check + ruff format --check)

Part 1 of 6 in the MuJoCo simulation PR decomposition (see PR_TASKS.md)

When a robot exposes more joints than the policy was trained on
(e.g. aloha has 16 joints but ACT expects 14), the policy raised a
hard ValueError during inference, making sim-to-real transfer fragile.

Fix: truncate excess joints or zero-pad if fewer, with debug logging.
This is the standard approach in robotics — LeRobot's own teleoperation
code does the same.
Address review feedback: state dimension truncation/padding should
be visible to operators since it can affect device behavior.
Address review: include robot_state_keys hint in truncation/padding
warnings so users can diagnose joint count mismatches.
Copy link
Copy Markdown

@yinsong1986 yinsong1986 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All review comments addressed. LGTM.

@cagataycali cagataycali merged commit 86938d3 into strands-labs:main Apr 3, 2026
1 check passed
@github-project-automation github-project-automation bot moved this from In review to Done in Strands Labs - Robots Apr 3, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

3 participants